package com.lancoo.znbkxx.teacher.ui.fragment

import android.annotation.SuppressLint
import android.view.View
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentTransaction
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.base.BaseVMFragment
import com.lancoo.znbkxx.teacher.databinding.FmtAddQuesBinding
import com.lancoo.znbkxx.teacher.viewmodel.HardSolutionViewModel
import kotlinx.android.synthetic.main.fmt_add_ques.*
import java.math.BigDecimal
import java.math.RoundingMode

/**
 * Created by wealive on 2021/3/1.
 *
 *
 */
class AddQuesFragment : BaseVMFragment<HardSolutionViewModel, FmtAddQuesBinding>() {
    val typeNo by lazy { arguments?.getString("typeNo") }
    val position by lazy { arguments?.getInt("position") }
    override fun setLayoutID(): Int {
        return R.layout.fmt_add_ques
    }

    override fun providerContext(): Any? {
        return activity
    }

    override fun providerVMClass(): Class<HardSolutionViewModel>? {
        return HardSolutionViewModel::class.java
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        viewModel.classicWrongQue.value?.let {
            tv_lost_percent.visibility = View.VISIBLE
            tv_lost_percent.text = "失分率:${BigDecimal(it[position!!].LoseRate * 100).setScale(0,
                    RoundingMode.HALF_UP)}%"
            tv_weak_num.visibility = View.VISIBLE
            tv_weak_num.text = "薄弱点:${it[position!!].WeakZSDNum}个"
        }
        val ft = childFragmentManager.beginTransaction()
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
        ft.replace(R.id.fcv,
                QuesAnalysisFragment().apply { arguments = bundleOf(Pair("position", position)) })
                .commit()
    }
}